import * as actions from '../actionTypes/'

// import turtle
// t = turtle.Turtle()

// for c in ['green', 'red', 'yellow', 'black']:
//     t.color(c)
//     t.forward(80)
//     t.left(90)

// 建议全屏模式呦
// import turtle
// import time
// turtle.pensize(2)
// turtle.speed(0)
// colors = ["red","yellow","purple","blue"]
// turtle.tracer(False)
// for x in range(200):
//     turtle.forward(2*x)
//     turtle.color(colors[x % 4])
//     turtle.left(92)
// turtle.tracer(True)

//编辑器里的默认code
export const defaultValue = `import turtle
# 定义变量
t = turtle.Turtle()
t.hideturtle()
greet = "欢迎来到可达鸭源码世界"
font=("Script MT Bold", 20, "bold")
colors = ["red", "orange","yellow"]
for a in range(10):
    t.color(colors[a%3])
    t.write(greet,align="center",font=font)
    t.left(90)
# 输出
print('hello, 可达鸭')
`

const editor = (
    state = {
        value: '',
        theme: 'solarized_light', // 'solarized_dark'
        showSidebar: true,
        showBlockly: false,
        consoles: '',
        isTurtleFullscreen: false,
        isPlaying: false,
        valueForId: '',
    },
    action
) => {
    switch (action.type) {
        case actions.HANDLE_EDITOR_CHANGE:
            return {
                ...state,
                value: action.payload,
            }
        case actions.PUT_EDITOR_VALUE:
            return {
                ...state,
                value: action.payload,
                valueForId: action.payload,
            }
        case actions.TOGGLE_EDITOR_THEME:
            return {
                ...state,
                theme: action.payload,
            }
        case actions.TOGGLE_DISPLAY_SIDEBAR:
            return {
                ...state,
                showSidebar: action.payload,
            }
        case actions.TOGGLE_DISPLAY_BLOCKLY:
            return {
                ...state,
                showBlockly: action.payload,
            }
        case actions.HANDLE_CLEAR_CONSOLE:
            return {
                ...state,
                consoles: '',
            }
        case actions.HANDLE_PUT_CONSOLE:
            return {
                ...state,
                consoles: state.consoles + action.payload,
            }
        case actions.TOGGLE_TURTLE_FULLSCREEN:
            return {
                ...state,
                isTurtleFullscreen: action.payload,
            }
        case actions.CREATE_NEW_PROJECT:
            return {
                ...state,
                value: '',
                consoles: '',
            }
        case actions.TOGGLE_PLAYING_TRURLE:
            return {
                ...state,
                isPlaying: action.payload,
            }
        default:
            return state
    }
}

export default editor



// WEBPACK FOOTER //
// ./src/reducers/editor.js